//添加当前页面主题监听

function sendTopic(conId,myHandler,selectName){
	 debugger;
	  var amq = org.activemq.Amq;  
	    amq.init({   
	      uri: 'amq', 
	      logging: true,
	      timeout: 10,  
	      clientId:(new Date()).getTime().toString()
	    }); 
	    amq.addListener("smeguangdong","topic://"+conId,myHandler,{selector:"name='"+selectName+"'"}); 
	
}





//查询订阅的消息主题启动监听接收消息


function findSub(id,type,myHandler,selectName){
	   var amq = org.activemq.Amq;  
	    amq.init({   
	      uri: 'amq', 
	      logging: true,
	      timeout: 5,
	      clientId:(new Date()).getTime().toString()
	    }); 
	    debugger;
	    $.ajax({  
	 	   type: "GET",
	 	   url: mqUrl+'/Mq/MQ/MQfindSub' ,
//	 	   url: 'http://192.168.1.120:8085/onehismq/Mq/MQ/MQfindSub' ,
	 	   data: {
		    	 userid : id,
		    	 type : type,
		    	 jsessionids:jsessionids
		     } ,
	 	   cache:false,
	 	   dataType: "jsonp",  
	 	   timeout : 1000, //超时
	 	   success: function(data, status){  
	 		  if(data !=null && data !=""){
		    		debugger;
		    		for(var i=0;i<data.length;i++ ){
						msgName=data[i].code;
		    			amq.addListener("smeguangdong","topic://"+data[i].code,myHandler,{selector:"name='"+selectName+"'"});
		    		}
		    		
		    	}
	 	   },  
	 	   
	 	});  
	
}

//查询注册发送的主题发送消息
//
function findTopicName(userid,type,vcb04,jieshoumessage){
	var topicName;
	$.ajax({
	     type: 'get',
	     url: mqUrl+'/Mq/MQ/MQfindSub' ,
        //此处查询自己订阅的消息topicName
	     data: {
	    	 userid : userid,
	    	 type :type,
	    	 jsessionids:jsessionids
	     } ,
	     dataType: "jsonp", 
	     async:false,
	     timeout : 1000, //超时
	     success: function(data){
	    	if(data !=null && data !=""){
	    		for(var i=0;i<data.length;i++ ){
	    			data[i].code;
	    			console.log(data[i].code);	
	    			topicName=data[i].code;
	    			MgTopicSend(vcb04,jieshoumessage,topicName);
	    		}	
	    		
	    	}
		  }
	  });
}

//消息发送函数
function  MgTopicSend(message,selectName,topicName){
	$.ajax({
	    async:false,
        cache: false,

	     type: 'get',
	     dataType: "jsonp", 
	     url: mqUrl+'/Mq/MQ/MQTopicSender' ,
	     data: {
	    	 topicName : topicName,
	    	 message   : message,
	    	 entityId  : "1",
	    	 selectName : selectName,
	    	 jsessionids:jsessionids
	     } ,
	     timeout : 1000, //超时
	     success: function (data){
	     } 


	  });
	
}


function MgAjaxSend(message){
var sendId =(new Date()).getTime().toString();
	
	//alert((new Date()).getTime().toString() );
	console.log((new Date()).getTime().toString());	
	//alert(id);
    var amq = org.activemq.Amq;  
    amq.init({   
      uri: 'amq', 
      logging: true,
      timeout: 1,  
      clientId:sendId
    });  
	amq.sendMessage("topic://"+topicName,message);
}




